package cn.rengy.web.framework.configure;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import cn.rengy.web.framework.antireptile.interceptor.AntiReptileInterceptor;
import cn.rengy.web.framework.security.AccessControlInterceptor;


@Configuration
public class WebMvcConfig implements WebMvcConfigurer{
	@Autowired(required=false)
	private AntiReptileInterceptor antiReptileInterceptor;
	
	@Autowired(required = false)
	private AccessControlInterceptor accessControlInterceptor;
	//ssl配置https://github.com/spring-projects/spring-boot/blob/v1.4.3.RELEASE/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java
	/*@Bean
	public EmbeddedServletContainerFactory servletContainer() {
		TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
		tomcat.addAdditionalTomcatConnectors(createStandardConnector());
		return tomcat;
	}
	@Value("${server.http.port}")
	private Integer port=80;
	private Connector createStandardConnector(){
		Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
		connector.setPort(port);
		return connector;
	}*/
	//改成配置文件配置
	/*@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		//设置静态资源访问，由spring处理静态资源
		registry.addResourceHandler("/**")
		.addResourceLocations("classpath:/webapp/");
		super.addResourceHandlers(registry);
	}*/
	
	@Override
    public void addCorsMappings(CorsRegistry registry) {
		//允许跨域访问
        registry.addMapping("/**");
    }
	
	@Override
    public void addInterceptors(InterceptorRegistry registry) {
		//registry.addInterceptor(accessControlInterceptor).excludePathPatterns("/view/**","/static/**","/favicon.ico","/error");
		if(antiReptileInterceptor!=null) {
			registry.addInterceptor(antiReptileInterceptor).excludePathPatterns("/view/**","/static/**","/favicon.ico","/error");
		}
    }
}
	
	
